package ThreadDemo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableDemo implements Callable<Integer> {
    public Integer call() throws Exception {
        int i = 0;
        for ( ; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
        return i;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableDemo callableDemo = new CallableDemo();
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callableDemo);
        for (int i = 0; i < 100; i++) {
            if (i == 20) {
                new Thread(futureTask,"有返回值的线程").start();
            }
        }
        System.out.println("子线程的返回值：" + futureTask.get());

    }
}
